#include "history.h"
CommandHistory::~CommandHistory(){
  ModifiedCommand *cmd;
  while(!undo_commands.empty()){
    cmd = undo_commands.top();
    undo_commands.pop();
    delete cmd;
  }
}
std::vector<ModifiedCommand*>
CommandHistory::get_last_n_cmd(int n){
    std::vector<ModifiedCommand*>ret;
    if(n <= 0) return ret;
    int ret_size = (n <= undo_commands.size())?n:undo_commands.size();
    for(int i = 0;i < ret_size;i++){
      ModifiedCommand *mcmd = undo_commands.top();
      undo_commands.pop();
      ret.push_back(mcmd);
    }
    reverse(ret.begin(),ret.end());
    for(int i = 0;i < ret.size();i++){
      undo_commands.push(ret[i]);
    }
    return ret;
}
